import requests

class IhrmEmpCURD(object):
    @classmethod
    def add_emp(cls,headers,json_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/"
        resp = requests.post(url=url,headers=headers,json=json_data)
        return resp
    @classmethod
    def query_emp(cls,emp_id,headers):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.get(url=url,headers=headers)
        return resp

    @classmethod
    def modify_emp(cls,emp_id,headers,data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.put(url=url,headers=headers,json=data)
        return resp

    @classmethod
    def delete_emp(cls,emp_id, headers):
        url = "http://ihrm2-test.itheima.net/api/sys/user/"+emp_id
        resp = requests.delete(url=url,headers=headers)
        return resp

if __name__ == '__main__':
    header = {"Content-Type": "application/json", "Authorization": "Bearer d6112591-c06a-4d9d-b3d0-a748c2da7041"}
    data_add = {
        "username": "业务猪001",
        "mobile": "13978734777",
        "workNumber": "9527"
    }
    resp = IhrmEmpCURD.add_emp(header, data_add)
    print("添加：", resp.json())

    emp_id = "1559425582737928192"
    resp = IhrmEmpCURD.query_emp(emp_id, header)
    print("查询：", resp.json())

    data = {"username": "齐天大圣"}
    resp = IhrmEmpCURD.modify_emp(emp_id, header, data)
    print("修改：", resp.json())

    resp = IhrmEmpCURD.delete_emp(emp_id, header)
    print("删除：", resp.json())

